﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
using MoneyWentWhere.Utils;

namespace MoneyWentWhere.OutputHelpers
{
    public class TableOptions
    {
        public String ColumnSeparator = "|";
        public bool ShowFullColumnName = false;
    }

    public static class TablePrinter
    {
        /// <summary>
        /// Print the given rows
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rows"></param>
        /// <returns></returns>
        public static String Print<T>(IEnumerable<T> rows)
        {
            return Print<T>(rows, new TableOptions());
        }

        /// <summary>
        /// Print the given rows
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public static String Print<T>(IEnumerable<T> rows, TableOptions options)
        {
            ObjectFieldColumn table = new ObjectFieldColumn(options);

            table.AddValues<T>(rows);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(table.Header);

            foreach (String val in table.Values)
            {
                sb.AppendLine(val);
            }
            return sb.ToString();
        }

        public static void ConsolePrint<T>(IEnumerable<T> rows)
        {
            Console.WriteLine(Print(rows));
        }
    }

}
